home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
422_02
/
misc
/
castle.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-20
|
46KB
|
1,441 lines
/*
* This is a text based adventure game which I wrote a number of
* years ago (on a unix system), and have since ported to the PC
* using MICRO-C.
*
* With thanks to Crowther and Woods who wrote the original FORTRAN
* adventure game from which this game borrows several ideas.
*
* Copyright 1983-1994 Dave Dunfield
* All rights reserved.
*
* Permission granted for personal (non-commercial) use only.
*
* Compile command: cc castle -fop
*/
#include <stdio.h>
#define OBJECTS 41 /* number of objects */
#define LOCS 181 /* number of locations */
#define DARK 16 /* first location where its dark */
#define DOORS 14 /* number of doors */
#define MONSTERS 12 /* number of monsters */
#define CARRY 5 /* carry limit */
#define STARTING_HITS 50 /* starting number of hit points */
#define LAMP_DIM_1 250 /* first warning */
#define LAMP_DIM_2 300 /* second warning */
#define LAMP_DIE 350 /* lamp dies */
#define RESUME_TIME 30 /* number of minites before he can resume */
#define EXTRA_POINTS 9 /* extra points for not breaking vase */
/* game status data, all data from 'prop' to start of 'inbuf' (exclusive) */
/* is saved in the file 'castle.sav' when game is suspended */
char prop[OBJECTS] = { 0 };
char door_stat[DOORS]= { 0 };
unsigned location[OBJECTS] = {
6, 4, 39, 8, 77, 33, 18, -1, 21, 24, 29,
92, 64, 108, 10, 144, 146, -1, -1, -1,
31, 67, 115, 65, 105, 79, 141, 41, 42, 117, -1,
-1, 96, 12, 90, 163, 128, 124, 11, 135, 164 };
char lstate = 1, died = 0, found_chest = 0;
unsigned carry = 0, turns = 0, lturns = 0, current_loc = 1,
old_loc = 1, deep = 0;
int hits = STARTING_HITS;
int monster_hits[] = { /* monsters current hit points */
10, 20, 25, 30, 40, 55, 60, 60, 75, 50, 100, 100 };
unsigned monster_loc[] = { /* monsters current location */
15, 25, 41, 55, 69, 83, 97, 111, 125, 139, 153, 167 };
unsigned date[2] = { 0 };
char inbuf[80], *inptr; /* input buffer and pointer */
unsigned places[LOCS]; /* stores pointers to descriptions */
char vocabulary[] = { /* known words */
/* verbs */
'g','o'+128, 1,
'r','u','n'+128, 1,
'w','a','l','k'+128, 1,
't','a','k','e'+128, 2,
'g','r','a','b'+128, 2,
'g','e','t'+128, 2,
'd','r','o','p'+128, 3,
'd','i','g'+128, 4,
'l','i','g','h','t'+128, 5,
'o','n'+128, 5,
'o','f','f'+128, 6,
'o','p','e','n'+128, 7,
'u','n','l','o','c','k'+128,7,
'm','o','v','e'+128, 7,
'p','u','s','h'+128, 7,
'r','e','m','o','v','e'+128,7,
'c','l','o','s','e'+128, 8,
'l','o','c','k'+128, 8,
'l','o','o','k'+128, 9,
'v','i','e','w'+128, 9,
'i','n','v','e','n','t','o','r','y'+128, 10,
'c','a','r','r','y'+128, 10,
'q','u','i','t'+128, 11,
's','t','o','p'+128, 11,
'r','e','a','d'+128, 12,
'w','a','v','e'+128, 13,
'r','u','b'+128, 13,
'o','p','e','r','a','t','e'+128, 13,
'u','s','e'+128, 13,
'a','b','r','a','c','a','d','a','b','r','a'+128, 14,
'h','o','k','u','s'+128,14,
'p','o','k','u','s'+128,14,
's','e','s','a','m','e'+128,14,
's','h','a','z','a','m'+128,14,
'p','l','u','g','h'+128, 14,
'x','y','z','z','y'+128, 14,
'f','a','r','l','e','y'+128,15,
's','u','s','p','e','n','d'+128,16,
'r','e','s','u','m','e'+128,17,
'a','t','t','a','c','k'+128,18,
's','w','i','n','g'+128, 18,
's','t','a','b'+128, 18,
't','h','r','u','s','t'+128,18,
'k','i','l','l'+128, 18,
'h','i','t'+128, 18,
'd','r','i','n','k'+128, 19,
'e','m','p','t','y'+128, 20,
'd','u','m','p'+128, 20,
's','p','i','l','l'+128, 20,
'r','e','t','r','e','a','t'+128,21,
'b','a','c','k','u','p'+128,21,
'l','a','s','t'+128, 21,
'b','a','c','k'+128, 21,
'o','u','t'+128, 21,
'o','i','l'+128, 22,
'l','u','b','r','i','c','a','t','e'+128,22,
's','c','o','r','e'+128, 23,
'p','o','i','n','t','s'+128,23,
's','h','i','t'+128, 24,
'f','u','c','k'+128, 24,
'd','a','m','n'+128, 24,
'p','i','s','s'+128, 24,
/* nouns */
'g','a','t','e'+128, 50,
'g','r','a','t','e'+128, 50,
'f','e','n','c','e'+128, 50,
'd','o','o','r'+128, 50,
's','l','a','b'+128, 50,
's','i','g','n'+128, 50,
'b','o','o','k','c','a','s','e'+128, 50,
's','h','e','l','v','e','s'+128, 50,
's','h','e','l','f'+128, 50,
'b','a','r','s'+128, 50,
'c','e','l','l'+128, 50,
'p','i','t'+128, 51,
'h','o','l','e'+128, 51,
's','t','a','i','r','s'+128,52,
'l','a','d','d','e','r'+128,52,
'w','a','l','l'+128, 53,
'c','a','v','e'+128, 53,
'c','a','v','e','r','n'+128,53,
'g','r','o','u','n','d'+128,53,
'f','l','o','o','r'+128, 53,
/* objects */
'l','a','m','p'+128, 100,
'l','a','n','t','e','r','n'+128,100,
'k','e','y'+128, 101,
'r','o','p','e'+128, 102,
's','t','r','i','n','g'+128,102,
'c','o','r','d'+128, 102,
'k','n','i','f','e'+128, 103,
'd','a','g','g','e','r'+128,103,
'a','x','e'+128, 104,
'h','a','t','c','h','e','t'+128,104,
's','w','o','r','d'+128, 105,
'h','i','l','t'+128, 105,
's','a','c','k'+128, 106,
'b','a','g'+128, 106,
'b','a','t','t','e','r','i','e','s'+128,107,
'b','a','t','t','e','r','y'+128,107,
'b','a','r'+128, 108,
'c','r','o','w','b','a','r'+128,108,
'r','o','d'+128, 109,
'w','a','n','d'+128, 109,
's','c','r','o','l','l'+128,110,
'p','a','p','e','r'+128, 110,
'r','o','l','l'+128, 110,
'p','o','t','i','o','n'+128,111,
'b','o','t','t','l','e'+128,111,
'f','l','a','s','k'+128, 112,
'l','i','q','u','i','d'+128,112,
'v','e','l','v','e','t'+128,113,
'p','i','l','l','o','w'+128,113,
'r','o','c','k'+128, 114,
's','t','o','n','e'+128, 114,
'p','u','r','p','l','e'+128,114,
'c','a','n','n','o','n'+128,115,
'b','a','l','l'+128, 115,
'm','e','t','a','l'+128, 116,
'd','e','t','e','c','t','o','r'+128,116,
/* treasure objects */
'c','o','i','n','s'+128, 120,
'm','o','n','e','y'+128, 120,
'r','i','n','g'+128, 121,
'b','a','n','d'+128, 121,
's','t','a','t','u','e'+128,122,
'c','r','y','s','t','a','l'+128,122,
'd','r','a','g','o','n'+128,122,
'i','v','o','r','y'+128, 123,
'a','m','u','l','e','t'+128,123,
'e','b','o','n','y'+128, 124,
'g','l','o','b','e'+128, 124,
'c','r','o','w','n'+128, 125,
'd','i','a','m','o','n','d'+128,126,
'g','o','l','d'+128, 127,
'n','u','g','g','e','t'+128,127,
'n','u','g','g','e','t','s'+128,127,
'p','r','e','c','i','o','u','s'+128,128,
'j','e','w','e','l','s'+128,128,
'j','e','w','e','l','r','y'+128,128,
'p','l','a','t','i','n','u','m'+128,129,
'p','y','r','a','m','i','d'+128,129,
'c','h','e','s','t'+128, 130,
't','r','e','a','s','u','r','e'+128,130,
'e','m','e','r','a','l','d'+128,131,
'e','a','r','r','i','n','g'+128,131,
'r','a','r','e'+128, 132,
's','p','i','c','e'+128, 132,
's','p','i','c','e','s'+128,132,
'p','e','r','s','i','a','n'+128,133,
'r','u','g'+128, 133,
'r','u','b','y'+128, 134,
's','t','a','f','f'+128, 134,
'm','i','n','g'+128, 135,
'v','a','s','e'+128, 135,
's','i','l','v','e','r'+128,136,
'p','e','n','d','a','n','t'+128,136,
'p','a','i','n','t','i','n','g'+128,137,
'a','r','t'+128, 137,
'b','r','o','n','z','e'+128,138,
'c','a','n','d','l','e'+128,138,
'c','a','n','d','l','e','s','t','i','c','k'+128,138,
's','i','l','k'+128, 139,
'j','a','c','k','e','t'+128,139,
's','i','l','k','e','n'+128,139,
'c','o','a','t'+128, 139,
'b','o','o','k'+128, 140,
'b','i','b','l','e'+128, 140,
'l','e','a','t','h','e','r'+128, 140,
/* directions */
'n','o','r','t','h'+128, 240,
'n'+128, 240,
'e','a','s','t'+128, 241,
'e'+128, 241,
's','o','u','t','h'+128, 242,
's'+128, 242,
'w','e','s','t'+128, 243,
'w'+128, 243,
'u','p'+128, 244,
'u'+128, 244,
'd','o','w','n'+128, 245,
'd'+128, 245,
/* filler words, not actually looked at, but no message given is used */
's','a','y'+128, 0,
't','h','e'+128, 0,
'a'+128, 0,
'w','i','t','h'+128, 0,
't','u','r'